package nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.concurrent.TimeUnit;

/**
 * program: io-share 
 * author: bsworld.xie 
 * create: 2021-04-15 14:48 
 * description: 
 */
public class NioServer {
    public static void main(String[] args) throws IOException, InterruptedException {
        ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
        serverSocketChannel.bind(new InetSocketAddress("127.0.0.1", 3888));
        serverSocketChannel.configureBlocking(false);
        SocketChannel clientSocket = serverSocketChannel.accept();
        long count = 0;
        while (clientSocket == null) {
            count++;
            clientSocket = serverSocketChannel.accept();
        }
        System.out.println("接收到新的连接:" + clientSocket + "，轮询次数:" + count);
        TimeUnit.SECONDS.sleep(100);

    }
}
